package com.itheima.app.task;

import com.itheima.domain.db.User;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.Sound;
import com.itheima.domain.mongo.UserSound;
import com.itheima.service.db.UserInfoService;
import com.itheima.service.mongo.SoundService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MyJob {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Reference
    UserInfoService userInfoService;
    @Reference
    SoundService soundService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void  task()
    {
        List<User>userList=userInfoService.findAllUser();
       //优化方案，每日更新之前，要将UserSound表里面的数据清空，然后在设置次数，其实这里面就很多的讲究，
        //如何合理的给每一个用户更新，用户注册？死亡用户？僵尸用户？都需要考虑；
        //同时也要考虑是否插入一定数量的假语音，没语音的怎么办？？
        for (User user : userList) {
            UserSound userSound=new UserSound();
            userSound.setUserId(user.getId());
            userSound.setRemaingTimes(10);
            soundService.savaUserSoound(userSound);

        }



    }
}
